/*
===========================================================================
Copyright (C) 2005 Sarunas

This file is part of MyPIRC source code.

DisksDB source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

DisksDB source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with DisksDB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
using System;
using System.Text.RegularExpressions;

namespace MyIRC
{
	/// <summary>
	/// User info
	/// </summary>
	public class ClientUser : IrcUser
	{
		public ClientUser(IrcClient server) : base(server, string.Empty, string.Empty, string.Empty)
		{
			this.nick = "Charlie" + Guid.NewGuid().ToString().Replace("{", "").Replace("}", "");
			this.realName = "Crarlie Root";
			this.ident = "charlieRoot";
			this.hostName = "localhost";
		}

		/// <summary>
		/// Sets, gets nick
		/// </summary>
		public override string Nick
		{
			get
			{
				return base.Nick;
			}
			set
			{
				if (null != value)
				{
					Regex r = new Regex("[ \t]");

					string[] val = r.Split(value);

					if (val.Length > 0)
					{
						this.UpdateNick(val[0]);
					}
				}
			}
		}

		public override string Ident
		{
			get
			{
				return base.Ident;
			}
			set
			{
				if (null != value)
				{
					Regex r = new Regex("[ \t]");

					string[] val = r.Split(value);

					if (val.Length > 0)
					{
						this.ident = val[0];
					}
				}
			}
		}

		public override string RealName
		{
			get
			{
				return base.RealName;
			}
			set
			{
				if ( (null != value) && (value.Length > 0) )
				{
					this.realName = value;
				}
			}
		}
	
		private void UpdateNick(string nick)
		{
			if (this.server.IsConnected)
			{
				this.server.SendMessage("NICK " + nick);
			}
			else
			{
				OnNickChanged(nick);
			}
		}
	}
}
